<?php

namespace app\yyq\controller;

use app\admin\model\Contact;
use app\yyq\validate\Contactus;
use think\Controller;
use think\exception\ValidateException;

class Callus extends Controller
{
    public function callus()
    {

        $data = $this->request->post();
        $res = new  Contact();
        //  添加验证，验证参数是否正确
        try {
            validate(Contactus::class)->scene('add')->check($data);
            $res->name = $data['name'];
            $res->email = $data['email'];
            $res->phone = $data['phone'];
            $res->address = $data['address'];
            $res->message = $data['message'];
            $res->state = 1;
            $res->create_time = time();
            $res->update_time = time();
            $res->save();
            return $this->fetch('callus', $this->getCommonData());
        } catch (ValidateException $e) {
            return $this->error($e->getError());
        }
    }


}